package com.jt.controller;

import com.jt.mapper.UserMapper;
import com.jt.pojo.User;
import com.jt.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Repository;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Controller
public class UserController {
    @Autowired
    private UserService userService;
//同步请求
    @RequestMapping("/findAll")
    public String findAll(Model model){
        List<User> userLis =
                userService.findAll();
        model.addAttribute("userList", userLis);
        return  "userList";
    }
    //异步请求
    @RequestMapping("toAjax")
    public String toAjax(){
        return "ajax";
    }
    @RequestMapping("/findAjax")
    @ResponseBody  //1.将返回值结果转化为JSON数据返回 2. 代表ajax请求结束
    public List<User> findAjax(Model model){

        return   userService.findAll();
    }
}
